/**
 * Created by jianglinjie on Wed Oct 11 2017
 */
'use strict';

var _config = require('../config');

var _config2 = _interopRequireDefault(_config);

var _register = require('../register');

var _register2 = _interopRequireDefault(_register);

var _captcha = require('../captcha');

var _captcha2 = _interopRequireDefault(_captcha);

var _CaptchaBusiness = require('../../constants/CaptchaBusiness');

var CaptchaBusiness = _interopRequireWildcard(_CaptchaBusiness);

var _randomJs = require('random-js');

var _randomJs2 = _interopRequireDefault(_randomJs);

var _StringUtils = require('../../utils/StringUtils');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

test('REGISTER_WITH_ACCOUNT', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  var userName, password, userInfo;
  return regeneratorRuntime.wrap(function _callee$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          console.log('apibasehost %s', _config2.default.apiBaseHost);

          userName = 'T' + new _randomJs2.default().string(10);
          password = '123456';
          _context.next = 5;
          return _register2.default.registerWithUserName(userName, password);

        case 5:
          userInfo = _context.sent;

          expect(userInfo.uid).toBeTruthy();
          expect(userInfo.userName).toMatch(userName);
          expect(userInfo.encryptPwd).toMatch((0, _StringUtils.md5)(password));

        case 9:
        case 'end':
          return _context.stop();
      }
    }
  }, _callee, undefined);
})));

test('REGISTER_WITH_PHONE', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  var phone, password, captchaResult, userInfo;
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
    while (1) {
      switch (_context2.prev = _context2.next) {
        case 0:
          console.log('apibasehost %s', _config2.default.apiBaseHost);
          phone = '1' + new _randomJs2.default().string(10, '0123456789');
          password = '123456';
          _context2.next = 5;
          return _captcha2.default.request({
            phone: phone,
            business: CaptchaBusiness.REGISTER
          });

        case 5:
          captchaResult = _context2.sent;
          _context2.next = 8;
          return _register2.default.registerWithPhone(phone, password, captchaResult.captcha);

        case 8:
          userInfo = _context2.sent;

          expect(userInfo.uid).toBeTruthy();
          expect(userInfo.phone).toMatch(phone);
          expect(userInfo.encryptPwd).toMatch((0, _StringUtils.md5)(password));

        case 12:
        case 'end':
          return _context2.stop();
      }
    }
  }, _callee2, undefined);
})));